package com.pinganfu.mock.control;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class HttpClientObject {
	
		public void http(String url,String json){
			//json = "{\"businessParameters\":{\"attach\":\"\",\"fee_type\":\"\",\"fund_trade_no\":\"009201510230000000297\",\"partner\":\"270\",\"retcode\":\"0000\",\"retmsg\":\"\",\"sign_key_index\":\"1\",\"sp_user\":\"00999000008334820\",\"time_end\":\"20151023140906\",\"total_fee\":\"9853.05\",\"total_fund_units\":\"9903.05\",\"transaction_id\":\"00500010201510230033330000463593\"},\"protocolParameters\":{\"channel_id\":\"PAF\",\"input_charset\":\"GBK\",\"service_version\":\"1.0\",\"sign\":\"47FF4944F159F95DB9F47FF5B4412F89B658A1C9\",\"sign_type\":\"SHA-1\"}}";
			//url="http://10.59.32.13:32800/caps/dhFundResponese.do";
			String resData="";
			HttpClient httpclient = new DefaultHttpClient();
		  	HttpPost post = new HttpPost(url);
		  	StringEntity entity = new StringEntity(json,"utf-8");//解决中文乱码问题   
		  	entity.setContentEncoding("UTF-8");    
		    entity.setContentType("application/json");    
		    post.setEntity(entity);
		    
		    HttpResponse result;
			try {
				result = httpclient.execute(post);
				resData = EntityUtils.toString(result.getEntity());
				System.out.println(resData);
				post.releaseConnection();
				
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		public static void main(String[] args) {
			HttpClientObject o = new HttpClientObject();
			try {
				Thread.sleep(1000);
				//o.http();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}
}
